package br.com.colegio.util;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashMD5
{
	/*
	 * param algoritmo : MD5, SHA-1, SHA-256
	 */
	public static String gerarHash(String texto, String algoritmo)
	{

		try
		{
			return (new BigInteger(1, MessageDigest.getInstance(algoritmo).digest(texto.getBytes()))).toString(16);
		}
		catch (NoSuchAlgorithmException e)
		{
			e.printStackTrace();
		}

		return null;
	}

	public static void main(String[] args)
	{
		System.out.println(HashMD5.gerarHash("123", "MD5"));
		System.out.println(HashMD5.gerarHash("123", "SHA-1"));
		System.out.println(HashMD5.gerarHash("123", "SHA-256"));

		System.out.println(HashMD5.gerarHash("gerando hash", "MD5"));
		System.out.println(HashMD5.gerarHash("gerando hash", "SHA-1"));
		System.out.println(HashMD5.gerarHash("gerando hash", "SHA-256"));
	}
}
